<?php
namespace Scan\Controller;

use Wechat\Controller\WxCustomerBaseController; 
use Org\Wechat\JSSDK;

class IndexController extends WxCustomerBaseController {
    
    protected $bookCatModel;
	protected $bookModel;
	protected $bookCodeModel;
	
	function _initialize() {
		parent::_initialize();
		
		$this->bookCatModel = D("Book/BookCat");
		$this->bookModel = D("Book/Book");
		$this->bookCodeModel = D("Book/BookCode");
	}
	
    /** 扫码借书页面 */
	public function scan() {
	    ///// JSSDK权限验证配置信息
	    $jssdk = new JSSDK($this->wxSetting['appid'], $this->wxSetting['appsecret']);
	    $signPackage = $jssdk->GetSignPackage();
	    $this->assign('signPackage', $signPackage);
        
	    // check customer
	    $customer = $this->customer;
	    if (!$customer) {
	        $this->display("../Customer:register");
			return;
	    }
	    $this->assign("customer", $customer);
	    
	    ///// go by action
	    $action = I('action');
	    
	    switch ($action) {
        case 'add_book':
	        $this->display(":book-add");
	        break;
        case 'borrow_book':
	        $this->display(":book-borrow");
	        break;
        case 'return_book':
	        $this->display(":book-return");
	        break;
        default:
            $this->assign("messageTitle", '返回扫码页面出错！');
			$this->error('参数错误！');
	        break;
	    }
		return;
    }

}
